package top.wardyan.wdev.dbdevassist.model;

import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import top.wardyan.base.model.BaseMasterModel;
import top.wardyan.base.util.DateUtil;
import top.wardyan.wdev.dbdevassist.po.Status;

@SuppressWarnings("serial")
public class YTDic extends MasterModel<YTDic>{

	public static final YTDic dao = new YTDic().dao();
	
	@Override
	public String tableName() {
		return "yt_dic";
	}
	
	private static Map<Integer, YTDic> maps = null;
	private static Timestamp deadline = null;
	private static final YTDic NULL = new YTDic().setSID(0).setXName("")
			.setSCreateTime(DateUtil.getCurrentTimestamp())
			.setSLastUpdate(DateUtil.getCurrentTimestamp()).setSStatus(1).setSVersion(0); 
	
	
	
	
	
	//private YTDic() {}
	
	public static YTDic getInstance(int sID, boolean isSingle){
		YTDic rs = null;
		if(isSingle) {
			rs = dao.findById(sID);
		}else {
			if(maps == null || maps.size() == 0 || deadline == null || DateUtil.getCurrentTimestamp().before(deadline)) {
				maps = new HashMap<>();
				//maps.clear();
				List<YTDic> dics = dao.findAll();
				if(dics != null) {
					for(YTDic d : dics) {
						maps.put(d.getSID(), d);
					}
				}
				deadline = new Timestamp(DateUtil.getCurrentTimestamp().getTime() + 60000);
			}
			//if(lists != null &&)
			if(maps != null) {
				rs = maps.get(sID);
			}
		}
		if(rs == null)
			rs = NULL;
		return rs;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public Status getSStatus() {
		//return this.getInt("sStatus");
		return Status.getInstance(this.getInt("sStatus"));
	}
	
	public YTDic setSStatus(Integer sStatus) {
		this.set("sStatus", sStatus);
		return this;
	}
	
	// xField xField2 xField3 xName xNote
//	public String getXField() {
//		return this.getStr("xField");
//	}
//	public YTDic setXField(String xField) {
//		this.set("xField", xField);
//		return this;
//	}
//	public String getXField2() {
//		return this.getStr("xField2");
//	}
//	public YTDic setXField2(String xField2) {
//		this.set("xField2", xField2);
//		return this;
//	}
//	public String getXField3() {
//		return this.getStr("xField3");
//	}
	public YTDic setXField3(String xField3) {
		this.set("xField3", xField3);
		return this;
	}
	public String getXName() {
		return this.getStr("xName");
	}
	public YTDic setXName(String xName) {
		this.set("xName", xName);
		return this;
	}
	public String getXNote() {
		return this.getStr("xNote");
	}
	public YTDic setXNote(String xNote) {
		this.set("xNote", xNote);
		return this;
	}
}
